// const localData = localStorage.getItem('pz_v3pz')
//这里的localData并没有配置conpoment
/* const state = localData ? localData.menu : {
  isCollapse: false,//实现菜单的展开与折叠
  selectMenu: [],//tag标签的展示
  routerList: []
} */
const state = {
  isCollapse: false,//实现菜单的展开与折叠
  selectMenu: [],//tag标签的展示
  routerList: [],
  menuActive: '1-1'
}
const mutations = {
  collapseMenu(state) {
    state.isCollapse = !state.isCollapse
  },

  addMenu(state, payload) {
    // console.log(payload, 'payload')
    if (state.selectMenu.findIndex(element => element.path === payload.path) === -1) {
      state.selectMenu.push(payload)
    }
  },
  closeMenu(state, payload) {
    const deleIndex = state.selectMenu.findIndex(element => payload.name === element.name)
    state.selectMenu.splice(deleIndex, 1)
  },
  dynamicMenu(state, payload) {
    // console.log(payload)
    //通过glob导入文件
    const modules = import.meta.glob('../views/**/**/*.vue')
    // console.log(modules)
    const routerSet = (router) => {
      router.forEach(element => {
        //判断有没有子菜单，若无，则为其拼接component
        if (!element.children) {
          const url = `../views${element.meta.path}/index.vue`
          element.component = modules[url]
        } else {
          routerSet(element.children)
        }
      });
    }
    routerSet(payload)
    //最终的路由数据,routerList得到的就是已经配置好组件的数组
    state.routerList = payload
    // console.log(state.routerList)
  },
  changeActive(state, payload) {
    state.menuActive = payload
    // console.log(state.menuActive)
  }
}
export default {
  state,
  mutations,
}



